/*
 * @Date         : 2022-06-14 13:48:32
 * @LastEditors  : zu1662
 * @LastEditTime : 2024-05-24 15:12:37
 * @Description  : 文章详情数据输出序列化
 *
 * Copyright © 2022 by zu1662, All Rights Reserved.
 */
import { Exclude, Transform, Type } from 'class-transformer';
import dayjs from 'dayjs';

export class ArticleDetailSerialization {
  @Type(() => String)
  readonly id: string;

  readonly title: string;

  readonly email: string;

  readonly cover: string;

  readonly summary: string;

  readonly content: string;

  readonly html: string;

  readonly toc: string;

  readonly status: string;

  readonly views: number;

  readonly likes: number;

  readonly isRecommended: boolean;

  readonly isCommentable: boolean;

  readonly needPassword: boolean;

  readonly password: string;

  @Transform(
    ({ value }) => {
      return dayjs(value).format('YYYY-MM-DD HH:mm:ss');
    },
    { toClassOnly: true }
  )
  readonly publishAt: Date;

  @Transform(
    ({ value }) => {
      return dayjs(value).format('YYYY-MM-DD HH:mm:ss');
    },
    { toClassOnly: true }
  )
  readonly createdAt: Date;

  @Exclude()
  @Transform(
    ({ value }) => {
      return dayjs(value).format('YYYY-MM-DD HH:mm:ss');
    },
    { toClassOnly: true }
  )
  readonly updatedAt: Date;
}
